package cn.com.dstz.data.post;

import org.apache.commons.lang.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;

/**
 * 分析POST
 * 接收三个参数
 * topaid, title, content
 * @author 叶装装
 *
 */
public class AnalysisKeyVal extends PostKeyVal{
	private Object topaid;
	private String content;
	private String title;
	
	public AnalysisKeyVal( Object topaid, String title, String content ){
		super( );
		this.topaid = topaid;
		this.title = deleteWhiteSpace( title );
		this.content = deleteWhiteSpace( content );
	}
	
	/**
	 * 参数格式：
	 * "paramStr=fenxi~!^$"	+admin.get( "topaid" )+"~!^$" +title.replaceAll(" ", "")	+ "|@!@|"+content.replaceAll(" ", ""));
	 */
	@Override
	public String processValue( ) {
		StringBuffer buffer = new StringBuffer( );
		
		appendToBufferWithDefaultSep(buffer, "fenxi", true );
		appendToBufferWithDefaultSep(buffer, topaid, true );
		appendToBufferWithAtSep(buffer, title, true );
		
		// content=content.length()<101?content:(content.indexOf("&")>95?content.substring(0, 95):content.substring(0, 100)); 
		// 按照原代码的意思就是内容在去除了所有的HTML标签之后，长度<101的，就直接发送, 就是前100个字符.
		// 否则： 为什么要判断& 这个不是很明白。。 总之只发送100个字符....
		if( StringUtils.isNotBlank( content ) ){
			content = Jsoup.clean( content, Whitelist.none( ) ); // 去除所有的标签
			if( content.length( ) > 100 ){
				content = content.substring( 0, 100 );
			}
		}
		
		appendToBufferWithDefaultSep(buffer, content, false );
		
		return buffer.toString( );
	}

	public Object getTopaid( ) {
		return topaid;
	}

	public void setTopaid( Object topaid ) {
		this.topaid = topaid;
	}

	public String getContent( ) {
		return content;
	}

	public void setContent( String content ) {
		this.content = content;
	}

	public String getTitle( ) {
		return title;
	}

	public void setTitle( String title ) {
		this.title = title;
	}

}
